package com.common.core;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.lang.NonNull;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;

import com.base.common.mvc.DefaultWebMvcExtConfiguration;
import com.common.mvc.AuthorityInterceptor;

import io.micrometer.core.instrument.MeterRegistry;

/**
 * Web配置
 * 
 * @author start
 *
 */
@Configuration
public class WebMvcConfiguration extends DefaultWebMvcExtConfiguration {
	
	@Bean
	public AuthorityInterceptor authorityInterceptor() {
		return new AuthorityInterceptor();
	}

	@Override
	public void addInterceptors(@NonNull InterceptorRegistry registry) {
		registry.addInterceptor(authorityInterceptor()).addPathPatterns("/**");
	}
	
	@Value("${spring.application.name}") 
	private String applicationName;
	
	@Bean
    public MeterRegistryCustomizer<MeterRegistry> meterRegistry(){
        return registry -> registry.config().commonTags("application", applicationName);
    }
	
}
